<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>
<body>
 <h1>登录</h1>
      <p>用户名 : <input type="text" id="username"></p>
      <p>密&nbsp;&nbsp;&nbsp;码 : <input type="text" id="password"></p>
      <p><button id="btn">登录</button></p>
	<script type="text/javascript">
		document.querySelector("#btn").onclick = function(){
		      // 1. 获取数据
		      var username_value = document.querySelector("#username").value;
		      var password_value = document.querySelector("#password").value;
			  //发送数据和请求
			  
			  let xhr=new XMLHttpRequest()
			  //按配置xhr
			  //post请求数据放在了请求体中\
			  
			  let date="username="+username_value+"&password="+password_value
				xhr.open("POST","js_POSTproject.php")
				//如果要发送POST请求 一定要在发送请求前 加入请求头设置
				//请求的内容类型换成 表格-url编码类型
			 xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
				//发送请求
			  xhr.send(date)
			  //返回响应
			  xhr.onreadystatechange=function(){
				  if(xhr.readyState===4){
					  
					 if( xhr.responseText === "登录成功"){
					       alert("恭喜登录成功");
					 }else{
					       alert("抱歉，请重新登录!");
					 }
				  
				  
			  }
			  
			  }
			  }
		
	</script>

</body>
</html>